package com.example.controller;

import com.example.model.util.PageUtils;
import com.example.impl.WxbGoodsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("goods")
public class WxbGoodsController {

    @Autowired
    private WxbGoodsServiceImpl wxbGoodsService;

    @RequestMapping( "/list")
    @ResponseBody
    public PageUtils list(Integer pageNum){

        PageUtils page = wxbGoodsService.list(pageNum);
        return page;
    }

    @RequestMapping("/list2")
    @ResponseBody
    public PageUtils listByType(String typeId,int pageNum){

        PageUtils page =wxbGoodsService.listByType(typeId,pageNum);

        return  page;
    }

    @RequestMapping("/updatestate")
    @ResponseBody
    public HashMap<String,Object> updateState(@RequestBody HashMap<String,Object> map){

        HashMap<String,Object> result = new HashMap<>();
        int state  =(Integer)map.get("state");
       List<String> ids = (List<String>) map.get("ids");
        try {
            wxbGoodsService.updateState(state,ids);
            result.put("code",1);
            result.put("msg","success");
        }catch(Exception e){
            e.printStackTrace();
            result.put("code",0);
            result.put("msg","file");

        }
        return result;
    }

}
